﻿using System.ServiceModel;
using System;
using System.Collections.Generic;
using Apprenda.SaaSGrid.Subscription;
using Apprenda.SaaSGrid;

namespace SaaSKit.Taskr.Service
{
    [ServiceContract(Namespace = "SaaSKit.Taskr.Service", Name = "CoreService")]
    public interface ICoreService
    {
        /// <summary>
        /// Creates a new task based on the information specified in the dto.
        /// </summary>
        /// <param name="task">A representation of what the new task data should be.</param>
        /// <returns>The id of the newly created task</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.CreateTask",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.CreateTaskReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        [FaultContract(typeof(LimiterExhaustedDetail), Action = "urn:SaaSKit.Fault")]
        Guid CreateTask(TaskDTO task);

        /// <summary>
        /// Updates an existing task based on it's id and the passed in data.
        /// </summary>
        /// <param name="task">The new data for the task. The task will be matched
        /// based on the id.</param>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.UpdateTask",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.UpdateTaskReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        [FaultContract(typeof(LimiterExhaustedDetail), Action = "urn:SaaSKit.Fault")]
        void UpdateTask(TaskDTO task);

        /// <summary>
        /// Deletes a task based on it's id.
        /// </summary>
        /// <param name="taskId">The unique identifier of the task to delete.</param>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.DeleteTask",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.DeleteTaskReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        void DeleteTask(Guid taskId);

        /// <summary>
        /// Retrieves a specific task based on it's unique identifier.
        /// </summary>
        /// <param name="taskId">The unique identifier of the task being retrieved.</param>
        /// <returns>Returns the task with the matching identifier.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.GetTask",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.GetTaskReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        TaskDTO GetTask(Guid taskId);

        /// <summary>
        /// Method to post activity for a task. The activity will be posted
        /// to the proper task based on the TaskId property of the activity.
        /// </summary>
        /// <param name="activity">The data to be posted as new activity.</param>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.PostActivity",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.PostActivityReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        void PostActivity(ActivityDTO activity);

        /// <summary>
        /// Returns all of the tasks in the system.
        /// </summary>
        /// <returns>A collection of all of the tasks in the system.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.ListAllTasks",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.ListAllTasksReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        [FaultContract(typeof(NotAuthorizedDetail), Action = "urn:SaaSKit.Fault")]
        IList<TaskDTO> ListAllTasks();

        /// <summary>
        /// Returns all of the tasks in the system that have not yet been completed.
        /// </summary>
        /// <returns>Returns all of the active tasks in the system which are tasks
        /// that have not yet been completed.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.ListAllActiveTasks",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.ListAllActiveTasksReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        [FaultContract(typeof(NotAuthorizedDetail), Action = "urn:SaaSKit.Fault")]
        IList<TaskDTO> ListAllActiveTasks();

        /// <summary>
        /// Returns all of the completed tasks in the system.
        /// </summary>
        /// <returns>Returns all of the tasks in the system that have been completed.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.ListAllCompletedTasks",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.ListAllCompletedTasksReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        [FaultContract(typeof(NotAuthorizedDetail), Action = "urn:SaaSKit.Fault")]
        IList<TaskDTO> ListAllCompletedTasks();

        /// <summary>
        /// Returns all of the tasks in the system that have not yet been assigned.
        /// </summary>
        /// <returns>Returns all of the tasks that don't have an assignee.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.ListUnassignedTasks",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.ListUnassignedTasksReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        [FaultContract(typeof(NotAuthorizedDetail), Action = "urn:SaaSKit.Fault")]
        IList<TaskDTO> ListUnassignedTasks();

        /// <summary>
        /// Returns all of the tasks for a particular assignee.
        /// </summary>
        /// <param name="assigneeId">The id of the assignee that the tasks are being returned for.</param>
        /// <returns>Returns the tasks of the assignee.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.ListTasks",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.ListTasksReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        IList<TaskDTO> ListTasks(Guid assigneeId);

        /// <summary>
        /// Returns all of the tasks for a particular assignee that have not yet been completed.
        /// </summary>
        /// <param name="assigneeId">The id of the assignee that the tasks are being returned for.</param>
        /// <returns>Returns the none completed tasks of the assignee.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.ListActiveTasks",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.ListActiveTasksReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        IList<TaskDTO> ListActiveTasks(Guid assigneeId);

        /// <summary>
        /// Returns all of the tasks for a particular assignee that have already been completed.
        /// </summary>
        /// <param name="assigneeId">The id of the assignee that the tasks are being returned for.</param>
        /// <returns>Returns all of the completed tasks for the assignee.</returns>
        [OperationContract(Action = "urn:SaaSKit.Taskr.Service.ListCompletedTasks",
                           ReplyAction = "urn:SaaSKit.Taskr.Service.ListCompletedTasksReply")]
        [FaultContract(typeof(ApplicationFaultDetail), Action = "urn:SaaSKit.Fault")]
        IList<TaskDTO> ListCompletedTasks(Guid assigneeId);
    }
}
